<template>
  <header class="top-nav">
    <div class="nav-content">
      <button v-if="showBack" @click="goBack" class="back-btn">
        <ArrowLeft class="back-icon" />
      </button>
      
      <h1 v-if="title" class="nav-title">{{ title }}</h1>
      
      <div class="nav-actions">
        <button @click="handleSearch" class="action-btn">
          <Search class="action-icon" />
        </button>
        <button v-if="showAdd" @click="handleAdd" class="action-btn">
          <Plus class="action-icon" />
        </button>
      </div>
    </div>
  </header>
</template>

<script setup lang="ts">
import { ArrowLeft, Search, Plus } from 'lucide-vue-next'
import { useRouter } from 'vue-router'

interface Props {
  title?: string
  showBack?: boolean
  showAdd?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  showBack: false,
  showAdd: false
})

const emit = defineEmits<{
  search: []
  add: []
}>()

const router = useRouter()

const goBack = () => {
  router.back()
}

const handleSearch = () => {
  emit('search')
}

const handleAdd = () => {
  emit('add')
}
</script>

<style lang="scss" scoped>
.top-nav {
  position: sticky;
  top: 0;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 999;
  box-shadow: var(--shadow-sm);
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md);
  max-width: 1200px;
  margin: 0 auto;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.3s ease;
  
  &:hover {
    background-color: var(--color-background);
    color: var(--color-primary);
  }
}

.back-icon {
  width: 20px;
  height: 20px;
}

.nav-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.nav-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.3s ease;
  
  &:hover {
    background-color: var(--color-background);
    color: var(--color-primary);
  }
}

.action-icon {
  width: 20px;
  height: 20px;
}
</style>